<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>浏览器标签页通信</title>
</head>
<body>
<input type="text" id="info"/>

<div id="msg"></div>
<script>
  let channel = new BroadcastChannel("channel")
  channel.onmessage=function (e){
      document.getElementById("msg").innerHTML+=(`<p>other:${e.data}</p>`)
  }

  document.getElementById("info").onkeydown=function (e){
      if (e.key === "Enter"){
          channel.postMessage(this.value)
          document.getElementById("msg").innerHTML+=(`<p>me:${this.value}</p>`)
          this.value = "";
      }
  }

</script>
</body>
</html>